package com.shuwang.business.exception;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

@ControllerAdvice
public class ExceptionHandle
{

	@ExceptionHandler(NotFoundException.class)
	@ResponseStatus(value = HttpStatus.NOT_FOUND)
	@ResponseBody
	public ResponseErrorMessage handleNotFoundException(
			NotFoundException ex)
	{
		return new ResponseErrorMessage(HttpStatus.NOT_FOUND.value(), ex.getMessage());
	}
	
	@ExceptionHandler(BadRequestExitException.class)
	@ResponseStatus(value = HttpStatus.BAD_REQUEST)
	@ResponseBody
	public ResponseErrorMessage handleBadRequestExitException(
			BadRequestExitException ex)
	{
		return new ResponseErrorMessage(HttpStatus.BAD_REQUEST.value(), ex.getMessage());
	}

	@ExceptionHandler(ForbiddenException.class)
	@ResponseStatus(value = HttpStatus.FORBIDDEN)
	@ResponseBody
	public ResponseErrorMessage handleForbiddenRequestException(
			ForbiddenException ex)
	{
		return new ResponseErrorMessage(HttpStatus.FORBIDDEN.value(), ex.getMessage());
	}

	@ExceptionHandler(ConflictException.class)
	@ResponseStatus(value = HttpStatus.CONFLICT)
	@ResponseBody
	public ResponseErrorMessage handleConflictRequestException(
			ConflictException ex){
		return new ResponseErrorMessage(HttpStatus.CONFLICT.value(),ex.getMessage());
	}
}
